﻿Partial Public Class WelcomeScreen
    Public Sub LoadData(ByVal ShowDate As Date)
        Me.TextBox1.Text = ""
        Me.TextBox2.Text = ""
        Me.TextBox3.Text = ""

        Me.TextBox4.Text = ""
        Me.TextBox5.Text = ""
        Me.TextBox6.Text = ""

        Me.LabelDate.Content = ShowDate.ToLongDateString

        For Each curCargo As dbiWSF.FrameworkObjects.objCargoType In myWSFObjects.CargoTypes.Values
            Me.TextBox1.Text += "Cargo: " + curCargo.Description + vbCrLf

            Me.TextBox2.Text += "Inbound: " + _
                             getInbound(curCargo.CargoID, ShowDate, myWSFObjects.Warehouses(0)).ToString + _
                             " | Outbound: " + getOutbound(curCargo.CargoID, ShowDate, myWSFObjects.Warehouses(0)).ToString + vbCrLf

            Me.TextBox4.Text += "Cargo: " + curCargo.Description + vbCrLf
            Me.TextBox5.Text += "Inbound: " + _
                              getInbound(curCargo.CargoID, ShowDate, myWSFObjects.Warehouses(1)).ToString + _
                              " | Outbound: " + getOutbound(curCargo.CargoID, ShowDate, myWSFObjects.Warehouses(1)).ToString + vbCrLf
        Next
        Me.TextBox1.Text += vbCrLf
        Me.TextBox4.Text += vbCrLf
        Me.TextBox2.Text += vbCrLf
        Me.TextBox5.Text += vbCrLf

        Me.TextBox1.Text += "Total: Shipments"
        Me.TextBox2.Text += "Inbound: " + _
                             getTotalInbound(ShowDate, myWSFObjects.Warehouses(0)).ToString + _
                             " | Outbound: " + getTotalOutbound(ShowDate, myWSFObjects.Warehouses(0)).ToString

        Me.TextBox4.Text += "Total Shipments: "
        Me.TextBox5.Text += "Inbound: " + _
                             getTotalInbound(ShowDate, myWSFObjects.Warehouses(1)).ToString + _
                             " | Outbound: " + getTotalOutbound(ShowDate, myWSFObjects.Warehouses(1)).ToString

        For Each GenException As dbiWSF.FrameworkObjects.objGenericException In myWSFObjects.GetGenericExceptionsByWhse(myWSFObjects.Warehouses(0), ShowDate)
            Me.TextBox3.Text += GenException.Description + "   -   (" + GenException.objLoadingDock.Description + ")" + vbCrLf
        Next

        For Each GenException As dbiWSF.FrameworkObjects.objGenericException In myWSFObjects.GetGenericExceptionsByWhse(myWSFObjects.Warehouses(1), ShowDate)
            Me.TextBox6.Text += GenException.Description + "   -   (" + GenException.objLoadingDock.Description + ")" + vbCrLf
        Next

        Me.LabelWarehouse1.Content = myWSFObjects.Warehouses(0).Description
        Me.LabelWarehouse2.Content = myWSFObjects.Warehouses(1).Description

    End Sub

    Public Function getInbound(ByVal curCargoID As System.Guid, ByVal DateToSelect As Date, ByVal Warehouse As dbiWSF.FrameworkObjects.objWarehouse) As Long


        Dim linqShipmentCount = From whse As dbiWSF.FrameworkObjects.objWarehouse In myWSFObjects.Warehouses _
                                From lDock As dbiWSF.FrameworkObjects.objLoadingDock In whse.LoadingDocks _
                                From Shipment As dbiWSF.FrameworkObjects.objShipment In lDock.Shipments _
                                From OrdHead As dbiWSF.FrameworkObjects.objOrderHeader In Shipment.OrderHeaders _
                                From OrdDetail As dbiWSF.FrameworkObjects.objOrderDetail In OrdHead.OrderDetails _
                                Where whse.WarehouseID = Warehouse.WarehouseID _
                                And OrdDetail.CargoTypeID = curCargoID _
                                And Shipment.ShipmentType = dbiWSF.FrameworkObjects.ShipmentTypes.Inbound _
                                And Shipment.SchedStartTime.Date = DateToSelect.Date _
                                 Select Shipment


        Return linqShipmentCount.Distinct.Count()




    End Function

    Public Function getOutbound(ByVal curCargoID As System.Guid, ByVal DateToSelect As Date, ByVal Warehouse As dbiWSF.FrameworkObjects.objWarehouse) As Long


        Dim linqShipmentCount = From whse As dbiWSF.FrameworkObjects.objWarehouse In myWSFObjects.Warehouses _
                                From lDock As dbiWSF.FrameworkObjects.objLoadingDock In whse.LoadingDocks _
                                From Shipment As dbiWSF.FrameworkObjects.objShipment In lDock.Shipments _
                                From OrdHead As dbiWSF.FrameworkObjects.objOrderHeader In Shipment.OrderHeaders _
                                From OrdDetail As dbiWSF.FrameworkObjects.objOrderDetail In OrdHead.OrderDetails _
                                Where whse.WarehouseID = Warehouse.WarehouseID _
                                And OrdDetail.CargoTypeID = curCargoID _
                                And Shipment.ShipmentType = dbiWSF.FrameworkObjects.ShipmentTypes.Outbound _
                                And Shipment.SchedStartTime.Date = DateToSelect.Date _
                                 Select Shipment

        Return linqShipmentCount.Distinct.Count()


        'Return linqShipmentCount.Count




    End Function

    Public Function getTotalInbound(ByVal DateToSelect As Date, ByVal Warehouse As dbiWSF.FrameworkObjects.objWarehouse) As Long


        Dim linqShipmentCount = From whse As dbiWSF.FrameworkObjects.objWarehouse In myWSFObjects.Warehouses _
                                From lDock As dbiWSF.FrameworkObjects.objLoadingDock In whse.LoadingDocks _
                                From Shipment As dbiWSF.FrameworkObjects.objShipment In lDock.Shipments _
                                From OrdHead As dbiWSF.FrameworkObjects.objOrderHeader In Shipment.OrderHeaders _
                                From OrdDetail As dbiWSF.FrameworkObjects.objOrderDetail In OrdHead.OrderDetails _
                                Where whse.WarehouseID = Warehouse.WarehouseID _
                                And Shipment.ShipmentType = dbiWSF.FrameworkObjects.ShipmentTypes.Inbound _
                                And Shipment.SchedStartTime.Date = DateToSelect.Date _
                                 Select Shipment


        Return linqShipmentCount.Distinct.Count()




    End Function

    Public Function getTotalOutbound(ByVal DateToSelect As Date, ByVal Warehouse As dbiWSF.FrameworkObjects.objWarehouse) As Long


        Dim linqShipmentCount = From whse As dbiWSF.FrameworkObjects.objWarehouse In myWSFObjects.Warehouses _
                                From lDock As dbiWSF.FrameworkObjects.objLoadingDock In whse.LoadingDocks _
                                From Shipment As dbiWSF.FrameworkObjects.objShipment In lDock.Shipments _
                                From OrdHead As dbiWSF.FrameworkObjects.objOrderHeader In Shipment.OrderHeaders _
                                From OrdDetail As dbiWSF.FrameworkObjects.objOrderDetail In OrdHead.OrderDetails _
                                Where whse.WarehouseID = Warehouse.WarehouseID _
                                And Shipment.ShipmentType = dbiWSF.FrameworkObjects.ShipmentTypes.Outbound _
                                And Shipment.SchedStartTime.Date = DateToSelect.Date _
                                 Select Shipment

        Return linqShipmentCount.Distinct.Count()


        'Return linqShipmentCount.Count




    End Function
End Class
